package com.example;

import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class SokcetClass {
    public static void main(String[] args) {

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            final HttpGet httpGet = new HttpGet("https://blog.csdn.net/justry_deng/article/details/81042379");
            ResponseHandler<String> responseHandler = (response) -> {
                final int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == 200) {
                    final HttpEntity entity = response.getEntity();
                    return entity==null?null:EntityUtils.toString(entity);
                }else {
                    return "";
                }
            };
            final String body = httpClient.execute(httpGet, responseHandler);
            System.out.println(body);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
